#!/usr/bin/env python
# -*- coding:utf8 -*-
from core import base


class Student(base.BaseClass):
    """创建学生类"""
    def __init__(self, student_name, student_sex, student_school, student_classes):
        base.BaseClass.__init__(self)
        self.student_name = student_name
        self.student_sex = student_sex
        self.student_school = student_school
        self.student_classes = student_classes

    def student_registered(self):
        student_dict = {}
        print("欢迎进入学生注册系统")
        student_name = input("注册姓名：").strip()
        student_sex = input("性别：").strip()
        student_school = input("学校：").strip()
        student_class = input("班级：").strip()

        st1 = Student(student_name, student_sex, student_school, student_class)
        student_dict["姓名"] = st1.student_name
        student_dict["性别"] = st1.student_sex
        student_dict["学校"] = st1.student_school
        student_dict["班级"] = st1.student_classes

        base.BaseClass.save_file(self, "student", student_dict)

    def student_pay_fees(self):
        pass

    def student_view_grade(self):
        student_school = input("校名：").strip()
        student_class = input("班级：").strip()
        student_times = input("课次：").strip()
        student_name = input("姓名：").strip()
        class_grade_list = base.BaseClass.open_file(self, "class_grade")
        for i in class_grade_list:
            for j in i:
                if j["学校"] == student_school and j["班级"] == student_class and j["课次"] == student_times \
                   and j["姓名"] == student_name:
                    for key in j:
                        print(key, j[key],end='\n')

    def student_view_record(self):
        student_school = input("校名：")
        student_class = input("班级：")
        student_times = input("课次：")
        student_name = input("姓名：")
        class_grade_list = base.BaseClass.open_file(self, "class_record")
        for i in class_grade_list:
            for j in i:
                if j["学校"] == student_school and j["班级"] == student_class and j["课次"] == student_times \
                   and j["姓名"] == student_name:
                    for key in j:
                        print(key, j[key],end='\n')


class Student_view(Student):
    def __init__(self, student_name, student_sex, student_school, student_classes):
        Student.__init__(self, student_name, student_sex, student_school, student_classes)

    def login(self):
        menu = u'''
        ------欢迎进入学生管理视图------
        \033[32;1m1、注册
        2、交学费
        3、查看上课记录
        4、查看作业成绩
        5、返回
        \033[0m
        '''
        menu_dic = {
            '1': Student.student_registered,
            '2': Student.student_pay_fees,
            '3': Student.student_view_record,
            '4': Student.student_view_grade,
            '5': "logout",

        }
        if True:
            exit_flag = False
            while not exit_flag:
                print(menu)
                option = input("请选择：").strip()
                if option in menu_dic:
                    if int(option) == 5:
                        exit_flag = True
                    else:
                        menu_dic[option](self)
                else:
                    print("\033[31;1m输入错误，重新输入\033[0m")
